<template>
  <div id="app">
    <!-- 主体内容 -->
    <el-container>
      <!-- 左边导航栏 -->
      <el-aside class="menu" width="240px">
        <nv-menu />
      </el-aside>
      <!-- 页面内容 -->
      <el-container class="view-wrap">
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>

    <!-- 登录部分 -->
    <login v-if="isLogin"></login>
  </div>
</template>

<script>
import NvMenu from './components/common/NvMenu'
import login from './views/Login/login'

export default {
  name: 'App',
  data() {
    return {
      isLogin: this.$store.state.isLogin
    }
  },
  components: {
    NvMenu,
    login
  },
  created() {
    //在页面加载时读取sessionStorage里的状态信息
    if (sessionStorage.getItem('store')) {
      this.$store.replaceState(
        Object.assign(
          {},
          this.$store.state,
          JSON.parse(sessionStorage.getItem('store'))
        )
      )
    }
    //在页面刷新时将vuex里的信息保存到sessionStorage里
    window.addEventListener('beforeunload', () => {
      sessionStorage.setItem('store', JSON.stringify(this.$store.state))
    })
  }
}
</script>

<style lang="scss">
@import 'assets/css/resrt.css';
.view-wrap {
  .el-main {
    padding: 0;
  }
}
</style>
